﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using FileMonitor.Service.ProcessMonitor.Contract;
using FileMonitor.Service.ProcessMonitor.Model;

using FileMonitor.Service.Provider.FileMonitor;
using System.ServiceModel;


namespace FileMonitor.Client
{
    public partial class Form1 : Form
    {
        Dictionary<string, MonitorProcessInfo> listMis;
        public Form1()
        {
            InitializeComponent();
            this.girdProcessInfo.AutoGenerateColumns = true;
            BindProcessInfo();
        }
 



        private void btnRefresh_Click(object sender, EventArgs e)
        {
            BindProcessInfo();
        }

        private void GetProcessInfo()
        {
            using (ChannelFactory<IMonitorProcessService> channelFactory = new ChannelFactory<IMonitorProcessService>("FileMonitorProcessStateService"))
            {
                IMonitorProcessService channel = channelFactory.CreateChannel();
                listMis = channel.GetAllProcessInfo();
                
            }
        }

        private void BindProcessInfo()
        {
              GetProcessInfo();
              this.girdProcessInfo.DataSource = listMis.Values;
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            //if (e.ColumnIndex == 4)
            //{
            //    string processName = (string)this.dataGridView1.Rows[e.RowIndex].Cells[0].Value;
            //    FileListForm fileInfoForm = new FileListForm();
            //    MonitorProcessInfo ps = list.Find((p) => p.ProcessName == processName);
            //    if (ps != null)
            //    {
            //        Dictionary<string,FileInfo> files = ps.FileInfos;
            //        List<FileInfo> listFiles = new List<FileInfo>();
            //        foreach (FileInfo f in files.Values)
            //        {
            //            listFiles.Add(f);
            //        }
            //        fileInfoForm.BindFiles(listFiles);
            //    }
          
            //    fileInfoForm.ShowDialog();
            //}
        }
    }
}
